﻿Imports System.Web
Imports System.Collections.Specialized

Namespace AboutDNN.DNNMVC

    Public Interface IRequest

        Property QueryString() As NameValueCollection
        Property Form() As NameValueCollection
        Property Cookies() As HttpCookieCollection
        Property Headers() As NameValueCollection
        Property Files() As List(Of HttpPostedFile)
        Property ApplicationPath() As String
        Property RequestType() As String
        Property IsAuthenticated() As Boolean
        Property UserName() As String
        Property ServerVariables() As NameValueCollection

    End Interface

    Public Class ASPRequest
        Implements IRequest

        Dim _request As HttpRequest = HttpContext.Current.Request
        Private _files As List(Of HttpPostedFile)

        Public Property ApplicationPath() As String Implements IRequest.ApplicationPath
            Get
                Return _request.ApplicationPath
            End Get
            Private Set(ByVal value As String)
            End Set
        End Property

        Public Property Cookies() As System.Web.HttpCookieCollection Implements IRequest.Cookies
            Get
                Return _request.Cookies
            End Get
            Private Set(ByVal value As System.Web.HttpCookieCollection)
            End Set
        End Property

        Public Property Files() As System.Collections.Generic.List(Of System.Web.HttpPostedFile) Implements IRequest.Files
            Get
                If _files Is Nothing Then
                    _files = New List(Of HttpPostedFile)
                    If _request.Files.Count > 0 Then
                        For i = 0 To _request.Files.Count - 1
                            _files.Add(_request.Files(i))
                        Next
                    End If
                End If
                Return _files
            End Get
            Private Set(ByVal value As System.Collections.Generic.List(Of System.Web.HttpPostedFile))
            End Set
        End Property

        Public Property Form() As System.Collections.Specialized.NameValueCollection Implements IRequest.Form
            Get
                Return _request.Form
            End Get
            Private Set(ByVal value As System.Collections.Specialized.NameValueCollection)
            End Set
        End Property

        Public Property Headers() As System.Collections.Specialized.NameValueCollection Implements IRequest.Headers
            Get
                Return _request.Headers
            End Get
            Private Set(ByVal value As System.Collections.Specialized.NameValueCollection)
            End Set
        End Property

        Public Property IsAuthenticated() As Boolean Implements IRequest.IsAuthenticated
            Get
                Return _request.IsAuthenticated
            End Get
            Private Set(ByVal value As Boolean)
            End Set
        End Property

        Public Property UserName() As String Implements IRequest.UserName
            Get
                Return HttpContext.Current.User.Identity.Name
            End Get
            Private Set(ByVal value As String)
            End Set
        End Property


        Public Property QueryString() As System.Collections.Specialized.NameValueCollection Implements IRequest.QueryString
            Get
                Return _request.QueryString
            End Get
            Private Set(ByVal value As System.Collections.Specialized.NameValueCollection)
            End Set
        End Property

        Public Property RequestType() As String Implements IRequest.RequestType
            Get
                Return _request.RequestType
            End Get
            Private Set(ByVal value As String)
            End Set
        End Property

        Public Property ServerVariables() As NameValueCollection Implements IRequest.ServerVariables
            Get
                Return _request.ServerVariables
            End Get
            Private Set(ByVal value As NameValueCollection)
            End Set
        End Property

    End Class

End Namespace